<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>L2LB: hash_table.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Gerado por Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Estruturas&nbsp;de&nbsp;dados</span></a></li>
      <li class="current"><a href="files.html"><span>Ficheiros</span></a></li>
    </ul>
  </div>
<h1>hash_table.h</h1><a href="hash__table_8h.html">Ir para a documentação deste ficheiro.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef __HASH_TABLE_H</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define __HASH_TABLE_H</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="comment">/* implementation of a simple hash table</span>
<a name="l00005"></a>00005 <span class="comment"> *      -- thread safe functions as *_safe()</span>
<a name="l00006"></a>00006 <span class="comment"> *  -- resolve collisions by chaining</span>
<a name="l00007"></a>00007 <span class="comment"> * Direct comments, concerns, questions, bugs to:</span>
<a name="l00008"></a>00008 <span class="comment"> * kulesh [squiggly] isis.poly.edu</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;pthread.h&gt;</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="preprocessor">#include "<a class="code" href="list_8h.html">list.h</a>"</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include "<a class="code" href="hash__function_8h.html">hash_function.h</a>"</span>
<a name="l00015"></a>00015 
<a name="l00016"></a><a class="code" href="hash__table_8h.html#df4781875a3f7c7d3cd5b90f736a7e26">00016</a> <span class="preprocessor">#define BUCKET_BITLEN   32</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span>
<a name="l00018"></a><a class="code" href="hash__table_8h.html#3d5ec14056d7480c722de378cf762198">00018</a> <span class="keyword">typedef</span> int (*<a class="code" href="hash__table_8h.html#3d5ec14056d7480c722de378cf762198">keycmp_ptr</a>) (<span class="keyword">const</span> <span class="keywordtype">void</span> *, <span class="keyword">const</span> <span class="keywordtype">void</span> *, size_t);
<a name="l00019"></a>00019 
<a name="l00020"></a><a class="code" href="structhash__entry.html">00020</a> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> {
<a name="l00021"></a><a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">00021</a>         <span class="keyword">struct </span><a class="code" href="structlist__head.html">list_head</a> <a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>;
<a name="l00022"></a><a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">00022</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>;
<a name="l00023"></a><a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">00023</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>;
<a name="l00024"></a>00024 };
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 <span class="comment">/* a hash_table contains buckets full of hash_entries (See above).</span>
<a name="l00027"></a>00027 <span class="comment"> * keycmp() is used to compare the keys of hash_entries</span>
<a name="l00028"></a>00028 <span class="comment"> */</span>
<a name="l00029"></a><a class="code" href="structhash__table.html">00029</a> <span class="keyword">struct </span><a class="code" href="structhash__table.html">hash_table</a> {
<a name="l00030"></a><a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">00030</a>         <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>;
<a name="l00031"></a>00031 
<a name="l00032"></a><a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">00032</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">buckets</a>;
<a name="l00033"></a><a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">00033</a>         pthread_mutex_t *<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>;
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">00035</a>         pthread_mutex_t <a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">lock</a>;
<a name="l00036"></a><a class="code" href="structhash__table.html#9465a319f391f0a50a4a84362c40fe48">00036</a>         <a class="code" href="hash__table_8h.html#3d5ec14056d7480c722de378cf762198">keycmp_ptr</a> <a class="code" href="structhash__table.html#9465a319f391f0a50a4a84362c40fe48">keycmp</a>;
<a name="l00037"></a>00037 
<a name="l00038"></a>00038         <span class="comment">/* private variables */</span>
<a name="l00039"></a><a class="code" href="structhash__table.html#77da69e21124ac1097627ae23ae72ef5">00039</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structhash__table.html#77da69e21124ac1097627ae23ae72ef5">__ht_i</a>;
<a name="l00040"></a><a class="code" href="structhash__table.html#f971de29e1c0b18ae5dede92ac65645d">00040</a>         <span class="keyword">struct </span><a class="code" href="structlist__head.html">list_head</a> *<a class="code" href="structhash__table.html#f971de29e1c0b18ae5dede92ac65645d">pos</a>;
<a name="l00041"></a>00041 };
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="hash__table_8h.html#e9600b4d6f7ce6395d53b2858953c76f">00043</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#e9600b4d6f7ce6395d53b2858953c76f">hash_table_bucket_lock</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045         <span class="keywordflow">return</span> (pthread_mutex_lock(&amp;(t-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>[n])));
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a><a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">00048</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)
<a name="l00049"></a>00049 {
<a name="l00050"></a>00050         <span class="keywordflow">return</span> (pthread_mutex_unlock(&amp;(t-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>[n])));
<a name="l00051"></a>00051 }
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="hash__table_8h.html#6ee43184883ee97c4f19b4e85549b5dc">00053</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#6ee43184883ee97c4f19b4e85549b5dc">hash_table_lock</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055         <span class="keywordflow">return</span> (pthread_mutex_lock(&amp;(t-&gt;<a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">lock</a>)));
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="hash__table_8h.html#21dc15c7b9538d15e19afffca43d9053">00058</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#21dc15c7b9538d15e19afffca43d9053">hash_table_unlock</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060         <span class="keywordflow">return</span> (pthread_mutex_unlock(&amp;(t-&gt;<a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">lock</a>)));
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="preprocessor">#ifdef EBUSY</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#2c3068f078190c2b4d9416576a30f548">hash_table_bucket_locked</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)
<a name="l00065"></a>00065 {
<a name="l00066"></a>00066         <span class="keywordflow">return</span> (pthread_mutex_trylock((t-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>[n])) == EBUSY);
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#0ddc013a986dacb55b81875438bc2e0a">hash_table_locked</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071         <span class="keywordflow">return</span> (pthread_mutex_trylock(&amp;(t-&gt;<a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">lock</a>)) == EBUSY);
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 <span class="preprocessor">#else</span>
<a name="l00074"></a><a class="code" href="hash__table_8h.html#2c3068f078190c2b4d9416576a30f548">00074</a> <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#2c3068f078190c2b4d9416576a30f548">hash_table_bucket_locked</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076         <span class="keywordflow">return</span> 0;
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078 
<a name="l00079"></a><a class="code" href="hash__table_8h.html#0ddc013a986dacb55b81875438bc2e0a">00079</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#0ddc013a986dacb55b81875438bc2e0a">hash_table_locked</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t)
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081         <span class="keywordflow">return</span> 0;
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 <span class="preprocessor">#endif</span>
<a name="l00084"></a>00084 <span class="preprocessor"></span>
<a name="l00085"></a><a class="code" href="hash__table_8h.html#b80477ad6e8ad63b4ea83252c67392f1">00085</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#b80477ad6e8ad63b4ea83252c67392f1">hash_table_hash_code</a>(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t,
<a name="l00086"></a>00086                                        <span class="keyword">const</span> <span class="keywordtype">char</span> *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         <span class="keywordflow">return</span> (<a class="code" href="hash__function_8h.html#d1a1b70cff8b395958e4f62f1f02f1bc">__hash</a>(key, len) % t-&gt;<a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">buckets</a>);
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091 
<a name="l00092"></a><a class="code" href="hash__table_8h.html#fb170aef9a24093e681f4f136f5fc404">00092</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#fb170aef9a24093e681f4f136f5fc404">hash_table_hash_code_safe</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *t,
<a name="l00093"></a>00093                                             <span class="keyword">const</span> <span class="keywordtype">char</span> *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095         <span class="keywordtype">int</span> n;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097         <a class="code" href="hash__table_8h.html#6ee43184883ee97c4f19b4e85549b5dc">hash_table_lock</a>(t);
<a name="l00098"></a>00098         n = <a class="code" href="hash__function_8h.html#d1a1b70cff8b395958e4f62f1f02f1bc">__hash</a>(key, len) % t-&gt;<a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">buckets</a>;
<a name="l00099"></a>00099         <a class="code" href="hash__table_8h.html#21dc15c7b9538d15e19afffca43d9053">hash_table_unlock</a>(t);
<a name="l00100"></a>00100 
<a name="l00101"></a>00101         <span class="keywordflow">return</span> n;
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 
<a name="l00104"></a><a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">00104</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">hash_entry_init</a>(<span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *e,
<a name="l00105"></a>00105                                   <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *str, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00106"></a>00106 {
<a name="l00107"></a>00107 
<a name="l00108"></a>00108         <a class="code" href="list_8h.html#0ffe9d28c36d7b018a9cfae33bae45c0">INIT_LIST_HEAD</a>(&amp;(e-&gt;<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>));
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         <span class="keywordflow">if</span> (str) {
<a name="l00111"></a>00111                 <span class="keywordflow">if</span> ((e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a> = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)malloc(len)) == NULL)
<a name="l00112"></a>00112                         <span class="keywordflow">return</span> -1;
<a name="l00113"></a>00113                 memcpy(e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, str, len);
<a name="l00114"></a>00114                 e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a> = len;
<a name="l00115"></a>00115         }
<a name="l00116"></a>00116         <span class="keywordflow">return</span> 0;
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00119"></a><a class="code" href="hash__table_8h.html#2b79db78da4c673932780dc1178ae7d8">00119</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="hash__table_8h.html#2b79db78da4c673932780dc1178ae7d8">hash_entry_finit</a>(<span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *e)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121         <span class="keywordflow">if</span> (e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>)
<a name="l00122"></a>00122                 free(e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>);
<a name="l00123"></a>00123         e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a> = 0;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="hash__table_8h.html#7e37848bc7e0e4fe223f633949331aa4">00126</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="hash__table_8h.html#7e37848bc7e0e4fe223f633949331aa4">hash_table_init</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> b,
<a name="l00127"></a>00127                                   <a class="code" href="hash__table_8h.html#3d5ec14056d7480c722de378cf762198">keycmp_ptr</a> keycmp)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129 
<a name="l00130"></a>00130         h-&gt;<a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">buckets</a> = b;
<a name="l00131"></a>00131         pthread_mutex_init(&amp;(h-&gt;<a class="code" href="structhash__table.html#f4cefababf047c699eca5f45f8d4284e">lock</a>), NULL);
<a name="l00132"></a>00132 
<a name="l00133"></a>00133         <span class="keywordflow">if</span> ((h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a> =
<a name="l00134"></a>00134              (<span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *)malloc(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a>) * b)) ==
<a name="l00135"></a>00135             NULL)
<a name="l00136"></a>00136                 <span class="keywordflow">return</span> -1;
<a name="l00137"></a>00137 
<a name="l00138"></a>00138         <span class="keywordflow">if</span> ((h-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a> =
<a name="l00139"></a>00139              (pthread_mutex_t *) malloc(<span class="keyword">sizeof</span>(pthread_mutex_t) * b)) == NULL)
<a name="l00140"></a>00140                 <span class="keywordflow">return</span> -1;
<a name="l00141"></a>00141 
<a name="l00142"></a>00142         <span class="keywordflow">for</span> (--b; b != 0; --b) {
<a name="l00143"></a>00143                 <a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">hash_entry_init</a>(&amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[b]), NULL, 0);
<a name="l00144"></a>00144                 pthread_mutex_init(&amp;h-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>[b], NULL);
<a name="l00145"></a>00145         }
<a name="l00146"></a>00146 
<a name="l00147"></a>00147         <a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">hash_entry_init</a>(&amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[0]), NULL, 0);
<a name="l00148"></a>00148         pthread_mutex_init(&amp;h-&gt;<a class="code" href="structhash__table.html#75f86a63f6a0efb451750126133cdddc">bucket_locks</a>[0], NULL);
<a name="l00149"></a>00149 
<a name="l00150"></a>00150         <span class="keywordflow">if</span> (keycmp)
<a name="l00151"></a>00151                 h-&gt;<a class="code" href="structhash__table.html#9465a319f391f0a50a4a84362c40fe48">keycmp</a> = keycmp;
<a name="l00152"></a>00152         <span class="keywordflow">else</span>
<a name="l00153"></a>00153                 h-&gt;<a class="code" href="structhash__table.html#9465a319f391f0a50a4a84362c40fe48">keycmp</a> = &amp;memcmp;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155         <span class="keywordflow">return</span> 0;
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a><a class="code" href="hash__table_8h.html#506d39e2faf00001f5354fd67ffaf590">00158</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="hash__table_8h.html#506d39e2faf00001f5354fd67ffaf590">hash_table_finit</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160 
<a name="l00161"></a>00161         <span class="keywordflow">if</span> (h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>)
<a name="l00162"></a>00162                 free(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>);
<a name="l00163"></a>00163         h-&gt;<a class="code" href="structhash__table.html#4678419b52c36e8b949b17eb4843a420">buckets</a> = 0;
<a name="l00164"></a>00164 }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 <span class="comment">/* insert_hash_table()</span>
<a name="l00167"></a>00167 <span class="comment"> * @h: &amp;struct hash_table hash table to insert hash_entry into</span>
<a name="l00168"></a>00168 <span class="comment"> * @e: &amp;struct hash_entry</span>
<a name="l00169"></a>00169 <span class="comment"> * Description: inserts @e into @h using @e-&gt;key as key. not thread-safe.</span>
<a name="l00170"></a>00170 <span class="comment"> */</span>
<a name="l00171"></a><a class="code" href="hash__table_8h.html#b169c085175842723f0b8ef86d138f0c">00171</a> <span class="keywordtype">void</span> <a class="code" href="hash__table_8h.html#b169c085175842723f0b8ef86d138f0c">hash_table_insert</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00172"></a>00172                        <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *e,
<a name="l00173"></a>00173                        <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         <a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">hash_entry_init</a>(e, key, len);
<a name="l00178"></a>00178         n = <a class="code" href="hash__table_8h.html#b80477ad6e8ad63b4ea83252c67392f1">hash_table_hash_code</a>(h, key, len);
<a name="l00179"></a>00179         <a class="code" href="list_8h.html#0373c4b3c8ce51a451a569ad978b32e1" title="list_add - add a new entry : new entry to be added : list head to add it after">list_add</a>(&amp;(e-&gt;<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>), &amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[n].<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>));
<a name="l00180"></a>00180 }
<a name="l00181"></a>00181 
<a name="l00182"></a>00182 <span class="comment">/* insert_hash_table_safe()</span>
<a name="l00183"></a>00183 <span class="comment"> * @h: &amp;struct hash_table hash table to insert hash_entry into</span>
<a name="l00184"></a>00184 <span class="comment"> * @e: &amp;struct hash_entry</span>
<a name="l00185"></a>00185 <span class="comment"> * @key: use key to insert the hash_entry</span>
<a name="l00186"></a>00186 <span class="comment"> * @len: length of the key</span>
<a name="l00187"></a>00187 <span class="comment"> * Description: inserts @e into @h using @e-&gt;key as key. thread-safe.</span>
<a name="l00188"></a>00188 <span class="comment"> */</span>
<a name="l00189"></a><a class="code" href="hash__table_8h.html#fce52c7df56ac3debdbeb4cdd767823f">00189</a> <span class="keywordtype">void</span> <a class="code" href="hash__table_8h.html#fce52c7df56ac3debdbeb4cdd767823f">hash_table_insert_safe</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00190"></a>00190                             <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *e,
<a name="l00191"></a>00191                             <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195         <a class="code" href="hash__table_8h.html#a1824f6d7b4c63926ccdfd86eb020c08">hash_entry_init</a>(e, key, len);
<a name="l00196"></a>00196         n = <a class="code" href="hash__table_8h.html#fb170aef9a24093e681f4f136f5fc404">hash_table_hash_code_safe</a>(h, key, len);
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <a class="code" href="hash__table_8h.html#e9600b4d6f7ce6395d53b2858953c76f">hash_table_bucket_lock</a>(h, n);
<a name="l00199"></a>00199         <a class="code" href="list_8h.html#0373c4b3c8ce51a451a569ad978b32e1" title="list_add - add a new entry : new entry to be added : list head to add it after">list_add</a>(&amp;(e-&gt;<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>), &amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[n].<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>));
<a name="l00200"></a>00200         <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(h, n);
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 
<a name="l00203"></a>00203 <span class="comment">/* hash_table_lookup_key()</span>
<a name="l00204"></a>00204 <span class="comment"> * @h: hash table to look into</span>
<a name="l00205"></a>00205 <span class="comment"> * @str: the key to look for</span>
<a name="l00206"></a>00206 <span class="comment"> * @len: length of the key</span>
<a name="l00207"></a>00207 <span class="comment"> * Description: looks up the hash table for the presence of key. </span>
<a name="l00208"></a>00208 <span class="comment"> * Returns: returns a pointer to the hash_entry that matches the key. otherise returns NULL.</span>
<a name="l00209"></a>00209 <span class="comment"> * Notes: in the presence of duplicate keys the function returns the first hash_entry found.</span>
<a name="l00210"></a>00210 <span class="comment"> *                function is not safe from delections. </span>
<a name="l00211"></a>00211 <span class="comment"> *                function is not thread safe. </span>
<a name="l00212"></a>00212 <span class="comment"> */</span>
<a name="l00213"></a><a class="code" href="hash__table_8h.html#26234bcfb00e679df2eb4b8e1476a9d5">00213</a> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#26234bcfb00e679df2eb4b8e1476a9d5">hash_table_lookup_key</a>(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00214"></a>00214                                          <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *str,
<a name="l00215"></a>00215                                          <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00216"></a>00216 {
<a name="l00217"></a>00217         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a> = <a class="code" href="hash__table_8h.html#b80477ad6e8ad63b4ea83252c67392f1">hash_table_hash_code</a>(h, str, len);
<a name="l00218"></a>00218         <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *tmp;
<a name="l00219"></a>00219         <span class="keyword">struct </span><a class="code" href="structlist__head.html">list_head</a> *pos;
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         <a class="code" href="list_8h.html#b8b24e6660ab3760c923e4b4db3fa502" title="list_for_each - iterate over a list : the &amp;amp;struct list_head to use as a loop...">list_for_each</a>(pos, &amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[key].<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>)) {
<a name="l00222"></a>00222                 tmp = <a class="code" href="list_8h.html#26c976b7f654e70df318c1843e5094de" title="list_entry - get the struct for this entry : the &amp;amp;struct list_head pointer.">list_entry</a>(pos, <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a>, list);
<a name="l00223"></a>00223 
<a name="l00224"></a>00224                 <span class="keywordflow">if</span> ((tmp-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a> == len)
<a name="l00225"></a>00225                     &amp;&amp; (h-&gt;<a class="code" href="structhash__table.html#9465a319f391f0a50a4a84362c40fe48">keycmp</a>(tmp-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, str, tmp-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>) == 0))
<a name="l00226"></a>00226                         <span class="keywordflow">return</span> tmp;
<a name="l00227"></a>00227         }
<a name="l00228"></a>00228         <span class="keywordflow">return</span> NULL;
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 
<a name="l00231"></a>00231 <span class="comment">/* hash_table_lookup_key_safe()</span>
<a name="l00232"></a>00232 <span class="comment"> * @h: hash table to look into</span>
<a name="l00233"></a>00233 <span class="comment"> * @str: the key to look for</span>
<a name="l00234"></a>00234 <span class="comment"> * @len: length of the key</span>
<a name="l00235"></a>00235 <span class="comment"> * Description: looks up the hash table for the presence of key. </span>
<a name="l00236"></a>00236 <span class="comment"> * Returns: returns a pointer to the hash_entry that matches the key. otherise returns NULL.</span>
<a name="l00237"></a>00237 <span class="comment"> * Notes: in the presence of duplicate keys the function returns the first hash_entry found.</span>
<a name="l00238"></a>00238 <span class="comment"> *                function is not safe from delections. </span>
<a name="l00239"></a>00239 <span class="comment"> *                function is not thread safe. </span>
<a name="l00240"></a>00240 <span class="comment"> */</span>
<a name="l00241"></a><a class="code" href="hash__table_8h.html#c20b239fac318b4a3f07951f67443485">00241</a> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#c20b239fac318b4a3f07951f67443485">hash_table_lookup_key_safe</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00242"></a>00242                                               <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *str,
<a name="l00243"></a>00243                                               <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00244"></a>00244 {
<a name="l00245"></a>00245 
<a name="l00246"></a>00246         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a> = <a class="code" href="hash__table_8h.html#fb170aef9a24093e681f4f136f5fc404">hash_table_hash_code_safe</a>(h, str, len);
<a name="l00247"></a>00247         <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *tmp;
<a name="l00248"></a>00248         <span class="keyword">struct </span><a class="code" href="structlist__head.html">list_head</a> *pos;
<a name="l00249"></a>00249 
<a name="l00250"></a>00250         <a class="code" href="hash__table_8h.html#e9600b4d6f7ce6395d53b2858953c76f">hash_table_bucket_lock</a>(h, key);
<a name="l00251"></a>00251 
<a name="l00252"></a>00252         <a class="code" href="list_8h.html#b8b24e6660ab3760c923e4b4db3fa502" title="list_for_each - iterate over a list : the &amp;amp;struct list_head to use as a loop...">list_for_each</a>(pos, &amp;(h-&gt;<a class="code" href="structhash__table.html#8d603d6d232203d2e491b58c9c6dabc5">table</a>[key].<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>)) {
<a name="l00253"></a>00253                 tmp = <a class="code" href="list_8h.html#26c976b7f654e70df318c1843e5094de" title="list_entry - get the struct for this entry : the &amp;amp;struct list_head pointer.">list_entry</a>(pos, <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a>, list);
<a name="l00254"></a>00254 
<a name="l00255"></a>00255                 <span class="keywordflow">if</span> (memcmp(tmp-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, str, tmp-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>) == 0) {
<a name="l00256"></a>00256                         <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(h, key);
<a name="l00257"></a>00257                         <span class="keywordflow">return</span> tmp;
<a name="l00258"></a>00258                 }
<a name="l00259"></a>00259         }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261         <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(h, key);
<a name="l00262"></a>00262         <span class="keywordflow">return</span> NULL;
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <span class="comment">/* same as hash_table_lookup_key() but this function takes a valid hash_entry as input.</span>
<a name="l00266"></a>00266 <span class="comment"> * a valid hash_entry is the one that has key, len set appropriately. in other words, a</span>
<a name="l00267"></a>00267 <span class="comment"> * hash_entry that is the output of hash_entry_init()</span>
<a name="l00268"></a>00268 <span class="comment"> */</span>
<a name="l00269"></a><a class="code" href="hash__table_8h.html#251fb227e81f38d9c3526696e760ca31">00269</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#251fb227e81f38d9c3526696e760ca31">hash_table_lookup_hash_entry</a>(<span class="keyword">const</span> <span class="keyword">struct</span>
<a name="l00270"></a>00270                                                               <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00271"></a>00271                                                               <span class="keyword">const</span> <span class="keyword">struct</span>
<a name="l00272"></a>00272                                                               <a class="code" href="structhash__entry.html">hash_entry</a> *e)
<a name="l00273"></a>00273 {
<a name="l00274"></a>00274         <span class="keywordflow">return</span> (<a class="code" href="hash__table_8h.html#26234bcfb00e679df2eb4b8e1476a9d5">hash_table_lookup_key</a>(h, e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>));
<a name="l00275"></a>00275 }
<a name="l00276"></a>00276 
<a name="l00277"></a>00277 <span class="comment">/* same as hash_table_lookup_key_safe() but this function takes a valid hash_entry as </span>
<a name="l00278"></a>00278 <span class="comment"> * input. a valid hash_entry is the one that has key, len set appropriately. in other </span>
<a name="l00279"></a>00279 <span class="comment"> * words, a hash_entry that is the output of hash_entry_init()</span>
<a name="l00280"></a>00280 <span class="comment"> */</span>
<a name="l00281"></a><a class="code" href="hash__table_8h.html#652be46a5fbf96645b384492f8c04644">00281</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#652be46a5fbf96645b384492f8c04644">hash_table_lookup_hash_entry_safe</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a>
<a name="l00282"></a>00282                                                                    *h, <span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a>
<a name="l00283"></a>00283                                                                    *e)
<a name="l00284"></a>00284 {
<a name="l00285"></a>00285         <span class="keywordflow">return</span> (<a class="code" href="hash__table_8h.html#c20b239fac318b4a3f07951f67443485">hash_table_lookup_key_safe</a>(h, e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>));
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a><a class="code" href="hash__table_8h.html#41c85ba1ce95224217a063dc322f815c">00288</a> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#41c85ba1ce95224217a063dc322f815c">hash_table_del_key</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h, <span class="keyword">const</span> <span class="keywordtype">char</span> *str,
<a name="l00289"></a>00289                                       <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00290"></a>00290 {
<a name="l00291"></a>00291         <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *e;
<a name="l00292"></a>00292 
<a name="l00293"></a>00293         <span class="keywordflow">if</span> ((e = <a class="code" href="hash__table_8h.html#26234bcfb00e679df2eb4b8e1476a9d5">hash_table_lookup_key</a>(h, str, len)) == NULL)
<a name="l00294"></a>00294                 <span class="keywordflow">return</span> NULL;
<a name="l00295"></a>00295 
<a name="l00296"></a>00296         <a class="code" href="list_8h.html#e1cde0f50b85945cfff23be4fc1586f4" title="list_del_init - deletes entry from list and reinitialize it.">list_del_init</a>(&amp;(e-&gt;<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>));
<a name="l00297"></a>00297         <span class="keywordflow">return</span> e;
<a name="l00298"></a>00298 }
<a name="l00299"></a>00299 
<a name="l00300"></a><a class="code" href="hash__table_8h.html#700e46956ce396aebc18e2dc902d072a">00300</a> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#700e46956ce396aebc18e2dc902d072a">hash_table_del_key_safe</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00301"></a>00301                                            <span class="keyword">const</span> <span class="keywordtype">char</span> *str, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
<a name="l00302"></a>00302 {
<a name="l00303"></a>00303         <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *e;
<a name="l00304"></a>00304         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n = <a class="code" href="hash__table_8h.html#b80477ad6e8ad63b4ea83252c67392f1">hash_table_hash_code</a>(h, str, len);
<a name="l00305"></a>00305 
<a name="l00306"></a>00306         <a class="code" href="hash__table_8h.html#e9600b4d6f7ce6395d53b2858953c76f">hash_table_bucket_lock</a>(h, n);
<a name="l00307"></a>00307         <span class="keywordflow">if</span> ((e = <a class="code" href="hash__table_8h.html#26234bcfb00e679df2eb4b8e1476a9d5">hash_table_lookup_key</a>(h, str, len)) != NULL) {
<a name="l00308"></a>00308                 <a class="code" href="list_8h.html#e1cde0f50b85945cfff23be4fc1586f4" title="list_del_init - deletes entry from list and reinitialize it.">list_del_init</a>(&amp;(e-&gt;<a class="code" href="structhash__entry.html#da52d1b11e544cd19b58007cc3713069">list</a>));
<a name="l00309"></a>00309                 <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(h, n);
<a name="l00310"></a>00310                 <span class="keywordflow">return</span> e;
<a name="l00311"></a>00311         }
<a name="l00312"></a>00312 
<a name="l00313"></a>00313         <a class="code" href="hash__table_8h.html#48f875515f654fd00e016384de1f14d9">hash_table_bucket_unlock</a>(h, n);
<a name="l00314"></a>00314         <span class="keywordflow">return</span> NULL;
<a name="l00315"></a>00315 }
<a name="l00316"></a>00316 
<a name="l00317"></a><a class="code" href="hash__table_8h.html#3577eebac3c7b1338dc8b0bded0441ab">00317</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#3577eebac3c7b1338dc8b0bded0441ab">hash_table_del_hash_entry</a>(<span class="keyword">struct</span> <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00318"></a>00318                                                            <span class="keyword">struct</span> <a class="code" href="structhash__entry.html">hash_entry</a> *e)
<a name="l00319"></a>00319 {
<a name="l00320"></a>00320         <span class="keywordflow">return</span> (<a class="code" href="hash__table_8h.html#41c85ba1ce95224217a063dc322f815c">hash_table_del_key</a>(h, e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>));
<a name="l00321"></a>00321 }
<a name="l00322"></a>00322 
<a name="l00323"></a><a class="code" href="hash__table_8h.html#1e29b091dbabf9bdf181bd5ee7162162">00323</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keyword">struct </span><a class="code" href="structhash__entry.html">hash_entry</a> *<a class="code" href="hash__table_8h.html#1e29b091dbabf9bdf181bd5ee7162162">hash_table_del_hash_entry_safe</a>(<span class="keyword">struct</span>
<a name="l00324"></a>00324                                                                 <a class="code" href="structhash__table.html">hash_table</a> *h,
<a name="l00325"></a>00325                                                                 <span class="keyword">struct</span>
<a name="l00326"></a>00326                                                                 <a class="code" href="structhash__entry.html">hash_entry</a> *e)
<a name="l00327"></a>00327 {
<a name="l00328"></a>00328         <span class="keywordflow">return</span> (<a class="code" href="hash__table_8h.html#700e46956ce396aebc18e2dc902d072a">hash_table_del_key_safe</a>(h, e-&gt;<a class="code" href="structhash__entry.html#3c21183a4d6fc5a89fa790359792ca93">key</a>, e-&gt;<a class="code" href="structhash__entry.html#6f87c5657a590b7a848cc3f9a1d30d13">keylen</a>));
<a name="l00329"></a>00329 }
<a name="l00330"></a>00330 
<a name="l00337"></a><a class="code" href="hash__table_8h.html#6d96b1b753cb4969aaa7f782021bcf5b">00337</a> <span class="preprocessor">#define hash_entry(ptr, type, member) \</span>
<a name="l00338"></a>00338 <span class="preprocessor">        ((type *)((char *)(ptr)-(unsigned long)(&amp;((type *)0)-&gt;member)))</span>
<a name="l00339"></a>00339 <span class="preprocessor"></span>
<a name="l00340"></a>00340 <span class="comment">/*</span>
<a name="l00341"></a>00341 <span class="comment"> * @hentry: &amp;struct hash_entry</span>
<a name="l00342"></a>00342 <span class="comment"> * @htable: &amp;struct hash_table</span>
<a name="l00343"></a>00343 <span class="comment"> */</span>
<a name="l00344"></a><a class="code" href="hash__table_8h.html#ca4be66f0e2f9faa7c47324d54a7c172">00344</a> <span class="preprocessor">#define hash_table_for_each(hentry, htable)     \</span>
<a name="l00345"></a>00345 <span class="preprocessor">        for     ((htable)-&gt;__ht_i=0; ((htable)-&gt;__ht_i &lt; (htable)-&gt;buckets); ++((htable)-&gt;__ht_i))      \</span>
<a name="l00346"></a>00346 <span class="preprocessor">                for(((htable)-&gt;pos= (htable)-&gt;table[(htable)-&gt;__ht_i].list.next);               \</span>
<a name="l00347"></a>00347 <span class="preprocessor">                                ((htable)-&gt;pos != &amp;((htable)-&gt;table[(htable)-&gt;__ht_i].list)) &amp;&amp; \</span>
<a name="l00348"></a>00348 <span class="preprocessor">                                ((hentry) = ((struct hash_entry *)((char *)((htable)-&gt;pos)-(unsigned long)(&amp;((struct hash_entry *)0)-&gt;list))) );        \</span>
<a name="l00349"></a>00349 <span class="preprocessor">                                (htable)-&gt;pos= (htable)-&gt;pos-&gt;next)</span>
<a name="l00350"></a>00350 <span class="preprocessor"></span>
<a name="l00351"></a>00351 <span class="comment">/*</span>
<a name="l00352"></a>00352 <span class="comment"> * @hentry: &amp;struct hash_entry</span>
<a name="l00353"></a>00353 <span class="comment"> * @htable: &amp;struct hash_table</span>
<a name="l00354"></a>00354 <span class="comment"> * @pos: &amp;struct list_head</span>
<a name="l00355"></a>00355 <span class="comment"> * @hti: unsigned int</span>
<a name="l00356"></a>00356 <span class="comment"> */</span>
<a name="l00357"></a><a class="code" href="hash__table_8h.html#98de86153912bbf3fa3c88cf06be211e">00357</a> <span class="preprocessor">#define hash_table_for_each_safe(hentry, htable, pos, hti)      \</span>
<a name="l00358"></a>00358 <span class="preprocessor">        for     ((hti)=0; ((hti) &lt; (htable)-&gt;buckets); ++(hti)) \</span>
<a name="l00359"></a>00359 <span class="preprocessor">                for(((pos)= (htable)-&gt;table[(hti)].list.next);          \</span>
<a name="l00360"></a>00360 <span class="preprocessor">                                ((pos) != &amp;((htable)-&gt;table[(hti)].list)) &amp;&amp;    \</span>
<a name="l00361"></a>00361 <span class="preprocessor">                                ((hentry) = ((struct hash_entry *)((char *)((pos))-(unsigned long)(&amp;((struct hash_entry *)0)-&gt;list))) );        \</span>
<a name="l00362"></a>00362 <span class="preprocessor">                                (pos)= (pos)-&gt;next)</span>
<a name="l00363"></a>00363 <span class="preprocessor"></span>
<a name="l00364"></a>00364 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Gerado em Wed Sep 10 22:06:25 2008 para L2LB por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>
